home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / hotshot / __init__.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  3.4 KB  |  87 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''High-perfomance logging profiler, mostly written in C.'''
  5. import _hotshot
  6. from _hotshot import ProfilerError
  7. from warnings import warnpy3k as _warnpy3k
  8. _warnpy3k("The 'hotshot' module is not supported in 3.x, use the 'profile' module instead.", stacklevel = 2)
  9.  
  10. class Profile:
  11.     
  12.     def __init__(self, logfn, lineevents = 0, linetimings = 1):
  13.         if not lineevents or 1:
  14.             pass
  15.         self.lineevents = 0
  16.         if not linetimings or lineevents or 1:
  17.             pass
  18.         self.linetimings = 0
  19.         self._prof = p = _hotshot.profiler(logfn, self.lineevents, self.linetimings)
  20.         if self.__class__ is Profile:
  21.             self.close = p.close
  22.             self.start = p.start
  23.             self.stop = p.stop
  24.             self.addinfo = p.addinfo
  25.         
  26.  
  27.     
  28.     def close(self):
  29.         '''Close the logfile and terminate the profiler.'''
  30.         self._prof.close()
  31.  
  32.     
  33.     def fileno(self):
  34.         """Return the file descriptor of the profiler's log file."""
  35.         return self._prof.fileno()
  36.  
  37.     
  38.     def start(self):
  39.         '''Start the profiler.'''
  40.         self._prof.start()
  41.  
  42.     
  43.     def stop(self):
  44.         '''Stop the profiler.'''
  45.         self._prof.stop()
  46.  
  47.     
  48.     def addinfo(self, key, value):
  49.         '''Add an arbitrary labelled value to the profile log.'''
  50.         self._prof.addinfo(key, value)
  51.  
  52.     
  53.     def run(self, cmd):
  54.         '''Profile an exec-compatible string in the script
  55.         environment.
  56.  
  57.         The globals from the __main__ module are used as both the
  58.         globals and locals for the script.
  59.         '''
  60.         import __main__
  61.         dict = __main__.__dict__
  62.         return self.runctx(cmd, dict, dict)
  63.  
  64.     
  65.     def runctx(self, cmd, globals, locals):
  66.         '''Evaluate an exec-compatible string in a specific
  67.         environment.
  68.  
  69.         The string is compiled before profiling begins.
  70.         '''
  71.         code = compile(cmd, '<string>', 'exec')
  72.         self._prof.runcode(code, globals, locals)
  73.         return self
  74.  
  75.     
  76.     def runcall(self, func, *args, **kw):
  77.         '''Profile a single call of a callable.
  78.  
  79.         Additional positional and keyword arguments may be passed
  80.         along; the result of the call is returned, and exceptions are
  81.         allowed to propogate cleanly, while ensuring that profiling is
  82.         disabled on the way out.
  83.         '''
  84.         return self._prof.runcall(func, args, kw)
  85.  
  86.  
  87.